home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / src.zoo / src / Write.c < prev   
Encoding:
C/C++ Source or Header  |  1989-03-17  |  1.3 KB  |  47 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: Write.c,v 1.1 89/03/17 08:20:28 sau Exp $
  9.     $Source: /m1/mgr.new/src/RCS/Write.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /m1/mgr.new/src/RCS/Write.c,v $$Revision: 1.1 $";
  12.  
  13. /* Long writes to ptty's don't always work */
  14.  
  15. #include <errno.h>
  16.  
  17. #define MAX_RETRY    3        /* max retries after EWOULDBLOCK */
  18. #define TTYMAX        100        /* max chunk size in write */
  19. #define Min(x,y)    ((x)<(y)?(x):(y))
  20.  
  21. extern errno;
  22.  
  23. int
  24. Write(fd,buff,len)
  25. register int fd, len;
  26. register char *buff;
  27.    {
  28.    register int count = 0;
  29.    register int code;
  30.    register int retry=0;
  31.  
  32.    while (count < len) {
  33.       code = write(fd,buff+count,Min(TTYMAX,len-count));
  34.       if (code > 0)
  35.          count += code;
  36.       else if (errno == EWOULDBLOCK) {
  37.          if (retry++ > MAX_RETRY)
  38.             break;
  39.          sleep(1);
  40.          continue;
  41.          }
  42.       else 
  43.          break;
  44.       }
  45.    return(count);
  46.    }
  47.